package com.itstation.neordo.ims.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.itstation.neordo.ims.model.Actor;
import com.itstation.neordo.ims.service.ActorService;

@Controller
public class ActorController {
	
	@Autowired
	private ActorService actorService;
	
	@RequestMapping(value="/actor/add")
	public ModelAndView addActorView(){
		ModelAndView modelAndView = new ModelAndView("add-actor-form");
		modelAndView.addObject("actor", new Actor());
		return modelAndView;
	}
	
	@RequestMapping(value="/actor/add/process")
	public ModelAndView addingActor(@ModelAttribute Actor actor){
		ModelAndView modelAndView = new ModelAndView("home");
		actorService.addActor(actor);
		
		String message = "Actor was successfully added";
		modelAndView.addObject("message", message);
		
		return modelAndView;
	}
	
	@RequestMapping(value="/actor/list")
	public ModelAndView listOfActors(){
		ModelAndView modelAndView = new ModelAndView("list-of-actors");
		List<Actor> actors = actorService.getActors();
		modelAndView.addObject("actors", actors);
		
		return modelAndView;
	}
}
